/**     
 * @Title: UserMgrImpl.java   
 * @Package com.yitong.mgr.impl   
 * @Description: TODO
 * @author weiwei 
 * @date 2017年7月20日 下午2:45:28   
 * @version V1.0     
 */
package com.yitong.mgr.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.yitong.dao.UserRepository;
import com.yitong.entity.User;
import com.yitong.mgr.UserMgr;

/**
 * @ClassName: UserMgrImpl
 * @Description: TODO
 * @author weiwei
 * @date 2017年7月20日 下午2:45:28
 * 
 */
@Service
@EnableTransactionManagement
public class UserMgrImpl implements UserMgr {

	@Autowired
	private UserRepository userRepository;

	@Override
	public User save(User user) {
		if (null != user) {
			return userRepository.save(user);
		}
		return null;
	}

	@Override
	public void updatePassword(String passwd, Integer id) {
		if (StringUtils.isNotBlank(passwd) && null != id) {
			userRepository.modifyPasswordById(passwd, id);
		}
	}

	@Override
	public User findById(Integer id) {
		if (null != id) {
			return userRepository.findOne(id);
		}
		return null;
	}

	@Override
	public List<User> findByUserName(String userName) {
		if (StringUtils.isNotBlank(userName)) {
			return userRepository.findByUserName(userName);
		}
		return null;
	}

	@Override
	public User findByEmailAndPassword(String email, String passwd) {
		if (StringUtils.isNotBlank(email) && StringUtils.isNotBlank(passwd)) {
			return userRepository.withEmailAndPasswordQuery(email, passwd);
		}
		return null;
	}
}